/****************************************************************************
 * Copyright (C) 2009-2010 SciTouch LLC
 * 
 * This file is part of Indigo toolkit.
 * 
 * This file may be distributed and/or modified under the terms of the
 * GNU General Public License version 3 as published by the Free Software
 * Foundation and appearing in the file LICENSE.GPL included in the
 * packaging of this file.
 * 
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 ***************************************************************************/

#include "molecule/icm_loader.h"
#include "base_cpp/scanner.h"
#include "molecule/cmf_loader.h"
#include "molecule/molecule.h"

IcmLoader::IcmLoader (Scanner &scanner) : _scanner(scanner)
{
}

void IcmLoader::loadMolecule (Molecule &mol)
{
   char id[3];

   _scanner.readCharsFix(3, id);
   if (strncmp(id, "ICM", 3) != 0)
      throw Error("expected 'ICM', got %.*s", 3, id);

   bool have_xyz = (_scanner.readChar() == 1);

   CmfLoader loader(_scanner);

   loader.loadMolecule(mol);

   if (have_xyz)
   {
      loader.loadXyz(_scanner);
      mol.getStereocenters().markBonds();
   }
}
